<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="n" uri="/newy" %>


<c:if test="${not empty page.result}">
<table class="table table-striped table-hover" id="wordTable">
    <thead>
        <tr>
            <th class="index">
                <input type="checkbox" class="idCheckAll" />
                序号
            </th>
            <th width="30%">学科编号</th>
            <th width="40%">学科名称</th>
           <%-- <th>学科组别</th>--%>
            <th>
                操作
            </th>
        </tr>
    </thead>


    <c:forEach items="${page.result}" var="subject" varStatus="sts">
        <tr>
            <td class="index">

                <input type="checkbox" class="idCheck" />
                    ${page.start + sts.index + 1}
                <input type="hidden" value="${subject.id}" class="hdSelectId" />
            </td>
            <td>
                    ${subject.number}
            </td>
            <td>
                    ${subject.name}

            </td>
<%--            <td>
                <c:if test="${subject.type==1}">
                    行政班课程
                </c:if>
                <c:if test="${subject.type==2}">
                    走班课程
                </c:if>
                <c:if test="${subject.type==3}">
                    兴趣班课程
                </c:if>
            </td>--%>
            <td>
                <a class="btn btn-primary" href="${pageContext.request.contextPath}/basic/subject/edit.do?id=${subject.id}"
                   data-toggle="modal" data-target="#modal">
                    编辑
                </a>
                <button class="btn btn-warning" onclick="deleteBt(${subject.id})">
                    <span class="glyphicon glyphicon-trash"></span>删除
                </button>

            </td>

        </tr>
    </c:forEach>
    </tbody>
</table>
    <div class="col-md-12" style="padding:0px;margin-top:10px;">
        <input type="checkbox" class="idCheckAll">&nbsp;&nbsp;全选
        &nbsp;&nbsp;
        <button class="btn btn-default" id="deleteAllBt">
            批量删除
        </button>
    </div>
    </c:if>
<c:if test="${empty page.result}">
    <ul class="media-list conversation-list">
        <li class="empty">暂无相关信息</li>
    </ul>
</c:if>

<jsp:include page="../../common/pager.jsp"></jsp:include>
<script>
    //全选
    $(".idCheckAll").click(function(){

        if($(this).is(":checked")){
            $(".idCheckAll").prop("checked",true);
            $('.idCheck').prop("checked",true);
        }
        else{
            $(".idCheckAll").prop("checked",false);
            $('.idCheck').prop("checked",false);
        }
    });
    //批量删除按钮
    $("#deleteAllBt").click(function () {
        var ids=[];
        for(var i=0;i<$(".idCheck").length;i++)
        {
            if($(".idCheck").eq(i).is(":checked"))
            {
                var id=$(".idCheck").eq(i).parent().find(".hdSelectId").val();
                ids.push(id);
            }
        }
        if(ids.length>0){
            var idStr=ids.join(",");
            layer.confirm("确定批量删除"+ids.length+"条数据吗？", {icon:3}, function () {
                $.ajax({
                    type: "POST",
                    url:projectPath+"/basic/subject/deleteAll.do",
                    data: {ids:idStr},
                    dataType:'json',
                    success: function (data) {
                        if(data.flag=="1"){
                            layer.msg("删除成功", {icon:1,time:1000,shade: 0.01});
                            creatPageList(1);
                        }else{
                            layer.msg("删除失败", {icon:2,time:1000,shade: 0.01});
                        }
                    }

                });
            });
        }else{
            layer.msg("未选择任何信息！", {icon: 7,time:1000,shade: 0.01});
        }
    });

</script>

